package org.myy.learn.hot.矩阵;

public class 矩阵置零 {
    //思路：遍历两遍。第一遍标记，第二遍处理
    public void setZeroes(int[][] matrix) {
        int m = matrix.length, n = matrix[0].length;
        boolean[] r = new boolean[m], c = new boolean[n]; //ToDo boolean默认值是false.Boolean默认值是null
        //标记
        for(int i=0; i<m; i++){
            for (int j=0; j<n; j++){
                if(matrix[i][j] == 0){
                    r[i] = c[j] = true;
                }
            }
        }
        //置零
        for(int i=0; i<m; i++){
            for (int j=0; j<n; j++){
                if(r[i] || c[j]){
                    matrix[i][j] = 0;
                }
            }
        }
    }
}
